package com.itheima.stock.controller;

import com.itheima.stock.pojo.domain.*;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import com.itheima.stock.vo.resp.UpDownWithTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 股票相关数据查询
 */
@Api(value = "/api/quot", tags = {"股票相关数据查询"})
@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    private StockService stockService;

    /**
     * 获取国内大盘数据
     * @return
     */
    @ApiOperation(value = "获取国内大盘数据", notes = "获取国内大盘数据", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getIndexAll(){
        return stockService.getIndexAll();
    }

    /**
     * 获取板块数据
     * @return
     */
    @ApiOperation(value = "获取板块数据", notes = "获取板块数据", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> sectorAll(){
        return stockService.sectorAllLimit();
    }

    /**
     * 获取涨幅榜
     * @return
     */
    @ApiOperation(value = "获取涨幅榜", notes = "获取涨幅榜", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<StockRfInfoDomain>> increase(){
        return stockService.increase();
    }

    /**
     * 统计最新交易日下股票每分钟涨跌停的数量
     * @return
     */
    @GetMapping("/stock/updown/count")
    public R<Map> getStockUpdownCount(){
        return stockService.getStockUpdownCount();
    }


    /**
     * 统计最近有效股票交易时间点下在各个区间的数量情况
     * @return
     */
    @ApiOperation(value = "统计最近有效股票交易时间点下在各个区间的数量情况", notes = "统计最近有效股票交易时间点下在各个区间的数量情况", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<UpDownWithTimeVo> getStockDown(){
        return stockService.getStockUpDown();
    }

    /**
     * 分页查询股票最新数据，并按照涨幅排序查询
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = ""),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "")
    })
    @ApiOperation(value = "分页查询股票最新数据，并按照涨幅排序查询", notes = "分页查询股票最新数据，并按照涨幅排序查询", httpMethod = "GET")
    @GetMapping("/stock/all")
    public R<PageResult> getStockPageInfo(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                                          @RequestParam(name = "pageSize",required = false,defaultValue = "20")Integer pageSize){
        return stockService.getStockPageInfo(page,pageSize);
    }



    /**
     * 涨幅数据导出
     * @param response
     * @param page  当前页
     * @param pageSize 每页大小
     */
    /*@GetMapping("/stock/export")
    public void stockExport(HttpServletResponse response, Integer page, Integer pageSize){
        stockService.stockExport(response,page,pageSize);
    }*/

    /**
     * 功能描述：统计国内A股大盘T日和T-1日成交量对比功能（成交量为沪市和深市成交量之和）
     * @return
     */
    @GetMapping("/stock/tradeAmt")
    public R<Map> stockTradeVol4InnerMarket(){
        return stockService.stockTradeVol4InnerMarket();
    }

    /**
     * 查询当前时间下股票的涨跌幅度区间统计功能
     * 如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询点
     * @return
     */
    @GetMapping("/stock/stock/updown")
    public R<Map> getStockUpDown(){
        return stockService.stockUpDownScopeCount();
    }

    /**
     * 功能描述：查询单个个股的分时行情数据，也就是统计指定股票T日每分钟的交易数据；
     *         如果当前日期不在有效时间内，则以最近的一个股票交易时间作为查询时间点
     * @param code 股票编码
     * @return
     */
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> stockScreenTimeSharing(String code){
        return stockService.stockScreenTimeSharing(code);
    }


    /**
     * 查询日K线数据
     * @param stockCode
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "stockCode", value = "", required = true)
    })
    @ApiOperation(value = "查询日K线数据", notes = "查询日K线数据", httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStockScreenDkLine(@RequestParam("code") String stockCode){
        return stockService.getStockScreenDkLine(stockCode);
    }


}
